package com.gongjian.web;

import com.github.pagehelper.PageHelper;
import com.gongjian.database.DatabaseFactory;
import org.apache.ibatis.session.SqlSession;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

import java.io.IOException;
import java.util.Properties;

/**
 * web服务 启动类
 * @author
 * @Description
 * @create 2019-03-20 15:25
 */
@SpringBootApplication
@ComponentScan("com.gongjian.database")
@ComponentScan("com.gongjian.web")
@ComponentScan("com.gongjian.utile")
public class webServiceApplication {
    public static void main(String[] args) {
        SpringApplication.run(webServiceApplication.class, args);
    }

    @Bean
    public SqlSession getSqlSeession() throws IOException {
        return DatabaseFactory.getSqlSession(false);
    }
    /**
     * //配置mybatis的分页插件pageHelper
     * @return
     */
    @Bean
    public PageHelper pageHelper() {
        PageHelper pageHelper = new PageHelper();
        Properties properties = new Properties();
        properties.setProperty("offsetAsPageNum", "true");
        properties.setProperty("rowBoundsWithCount", "true");
        properties.setProperty("reasonable", "true");
        //配置mysql数据库的方言
        properties.setProperty("dialect", "mysql");
        pageHelper.setProperties(properties);
        return pageHelper;

    }
}
